//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <stdio.h>
#include <PowerDef.h>
//example,not a real implementation.
#define LOWEST 13
#define VERYLOW 91//not used in real system
#define LOW 104
#define MEDIUM 208
#define HIGH 312
#define VERYHIGH 416
#define HEIGHTEST 416//the same as the veryhigh

//example,the VCC_CORE is valid between 0.85 - 1.3
const float MIN=(float)0.85;
const float V_LOW=(float)1.0;
const float V_HIGH=(float)1.15;
const float MAX=(float)1.3;

Mode cur_mode;//if in a real chip,it may be stored in some register.
unsigned Scale_GetCpuFrequency()
{//this function should be carefully tuned later in real environment.
    switch (cur_mode) {
        case Lowest:return LOWEST ;
        case VeryLow:return LOW ;
        case Low:return LOW ;
        case Medium:return MEDIUM ;
        case High:return HIGH  ;
        case VeryHigh:return VERYHIGH  ;
        case Heightest:return HEIGHTEST ;
        default:return LOWEST;
    }
}

float Scale_GetCpuVoltage()
{//this function should be carefully tuned later in real environment.
    switch (cur_mode) {
        case Lowest:return MIN ;
        case VeryLow:return V_LOW ;
        case Low:return V_LOW ;
        case Medium:return V_HIGH ;
        case High:return V_HIGH  ;
        case VeryHigh:return MAX  ;
        case Heightest:return MAX ;
        default:return MIN;
    }
}

void Scale_Initialize()
{//to implememt in the real chip.
    printf("scale is initialized\n");
}

void Scale(unsigned long mode)
{
    cur_mode=(Mode)mode;
    printf("scale the cpu to the new mode: %d",mode);
}

extern"C" unsigned long Scale_GetCpuMode()
{
    return (unsigned long)cur_mode;
}

extern"C" unsigned Scale_ComputeCpuPower()
{
    unsigned power=(unsigned)( Scale_GetCpuFrequency() * Scale_GetCpuVoltage() * Scale_GetCpuVoltage());
    return power;
}
